#include <stdio.h>
#include <stdlib.h>

//活动
typedef struct activity_t
{
int start;//起始时间
int end;//结束时间
} activity;

//和P227页的算法思路相同
void greedy_algorithm(activity* data, const int n)
{
if (n > 0)
{
    int sequence[n];
    int i;
    for (i = 0; i < n; i++)
    sequence[i] = -1;
    i = 0;
    sequence[i] = 0;
    int count = 0;
    int tmp = 0;
    while ((++count) < n)
    {
    if (data[count].start >= data[tmp].end)
    {
        sequence[++i] = count;
        tmp = count;
    }
    }
    int j;
    for (j = 0; j < n; j++)
    {
    if (sequence[j] == -1)
    break;
    printf("[%d,%d)\t", data[sequence[j]].start, data[sequence[j]].end);
    }
    printf("\n----------\n");

    //对于剩下的数据再调用本函数
    activity* remain_data = (activity*)malloc(sizeof(activity)*(n-j));
    int p;
    int q;
    int k = 0;
    for (p = 0; p < n; p++)
    {
    int flag = 0;
    for (q = 0; q < j; q++)
    {
        if (p == sequence[q])
        {
        flag = 1;
        break;
        }
    }
    if (flag == 0)
    {
        remain_data[k++] = data[p];
    }
    }
    greedy_algorithm(remain_data, n-j);
    free(remain_data);
}
}

int main()
{
int n;
scanf("%d", &n);
activity* data = (activity*)malloc(n*sizeof(activity));
activity a;
int rows = n;
//按照结束时间从小到大进行输入，P222页底下表格中的数据
while (rows--)
{
    scanf("%d%d", &(a.start), &(a.end));
    data[n-rows-1] = a;
}
greedy_algorithm(data, n);
free(data);
return 0;
}